//
//  MainViewController.swift
//  Status
//
//  Created by 花轮 on 15/5/10.
//  Copyright (c) 2015年 花轮. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @IBOutlet weak var maintabbar: MainTabBar!
    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewController()
        
        maintabbar.composeedButton.addTarget(self, action: "composeClick", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    func composeClick() {
        presentViewController(UIStoryboard.initialViewController("Compose"), animated: true, completion: nil)
    }
    
    func addChildViewController(){
        tabBar.tintColor = UIColor.orangeColor()

        addChildViewController("Home", "首页", "tabbar_home")
        addChildViewController("Message", "消息", "tabbar_message_center")
        addChildViewController("Discover", "发现", "tabbar_discover")
        addChildViewController("Profile", "我", "tabbar_profile")
    }
    
    func addChildViewController(sbName: String, _ title: String, _ imageName: String)
    {
        let sb = UIStoryboard(name: sbName, bundle: nil)
        // instantiateInitialViewController的类型是AnyObject，所以要转类型
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.topViewController.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        addChildViewController(nav)
    }
}
